const axios = require("axios");
const fs = require("fs");
const path = require("path");
const { promisify } = require("util");

const write = promisify(fs.writeFile);

const getHosts = async () => {
  try {
    const { data } = await axios.get(
      "https://raw.githubusercontent.com/googlehosts/hosts/master/hosts-files/hosts"
    );
    await write(path.resolve(__dirname, "../", "hosts"), data);
    console.log("The file \"hosts\" has been downloaded and saved to this projects's root directory");
  } catch (err) {
    console.log(err);
  }
};

getHosts();
